//
//  SearchDetailTableViewCell.swift
//  Wmsmobile
//
//  Created by wangshuning on 16/8/22.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit

class SearchDetailTableViewCell: UITableViewCell {

    //MARK: - property
    var info: Dictionary<String , String>?{
        didSet{
            labelLeft.text = info!["货品名称"] ?? ""
            labelRight.text = "\(info!["规格"] ?? "")/\(info!["件数"] ?? "")" 
            labelCenter.text = ""
            self.labelCenter.isHidden = true
            self.accessorView.isHidden = false
        }
    }
    
    lazy fileprivate var labelLeft:UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: (WMSFonts["founctionCell"]!)[userInfo!.fontLevel.rawValue])
        label.textColor = UIColor.hexStringToUIColor("#666666")
        return label
    }()
    lazy fileprivate var labelRight:UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: (WMSFonts["founctionCell"]!)[userInfo!.fontLevel.rawValue])
        label.textColor = UIColor.hexStringToUIColor("#666666")
        return label
    }()
    lazy var labelCenter:UILabel = {
        let label = UILabel()
        label.text = "无数据"
        label.font = UIFont.systemFont(ofSize: (WMSFonts["founctionCell"]!)[userInfo!.fontLevel.rawValue])
        label.textColor = UIColor.hexStringToUIColor("#666666")
        return label
    }()
    lazy fileprivate var accessorView:UIImageView = {
        let imView = UIImageView()
        imView.image = UIImage(named: "箭头icon")
        return imView
    }()
    lazy fileprivate var buton:UIButton = {
        let button = UIButton()
        return button
    }()
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        self.contentView.addSubview(labelLeft)//添加sunveiw
        self.contentView.addSubview(labelRight)
        self.contentView.addSubview(accessorView)
        self.contentView.addSubview(labelCenter)
        self.contentView.addSubview(buton)
        buton.addTarget(self, action: #selector(BinSpecTableviewCell.didSelected), for: UIControlEvents.touchUpInside)
        self.accessorView.isHidden = true
        //布局subview
        labelLeft.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(18)
            make.centerY.equalTo(self)
        }
        accessorView.snp.makeConstraints { (make) in
            make.trailing.equalTo(self).offset(-15)
            make.centerY.equalTo(self)
            make.width.equalTo(22)
            make.height.equalTo(22)
        }
        labelRight.snp.makeConstraints { (make) in
            make.trailing.equalTo(accessorView.snp.leading).offset(-10)
            make.centerY.equalTo(self)
        }
        labelCenter.snp.makeConstraints { (make) in
            make.center.equalTo(self)
        }
        buton.frame = self.bounds
    }
    
    
    func didSelected(){
        guard labelCenter.isHidden == true else {
            return
        }
        let vc = SearchDetailTableViewController(info: self.info!)
        self.parentController()?.navigationController?.pushViewController(vc, animated: true)
    }
    


}
